#ifndef STRAY_RESOURCE_FILE_H
#define STRAY_RESOURCE_FILE_H

#include <String\String.h>
#include <File\FileStream.h>
#include <Container\Map.h>
#include <Object\ReferenceObject.h>
#include <SmartPtr\SharedPtr.h>
#include <Thread\Mutex.h>
#include "ResFileData.h"

namespace Stray {
namespace Resource {

struct FileID
{
	Stray::String archiveName_;
	Stray::String fileName_;

	bool operator ==(const FileID& rhs) const
	{
		return (archiveName_ == rhs.archiveName_ && fileName_ == rhs.fileName_);
	}
};

size_t hash_value(const FileID& name);

enum ResourceFileState
{
	RFS_UNLOADED,
	RFS_LOADING,
	RFS_LOADED,
	RFS_UNLOADING,

	RFS_UNKNOWN,
};

class ResourceFile
{
protected:
	typedef Stray::String String;
	typedef Stray::Core::FileStream FileStream;
public:
	ResourceFile(const FileID& fileName) :
		id_(fileName)
	{
	}

	virtual ~ResourceFile(){}

	FileID getID() const
	{
		return id_;
	}

	ResourceFileState getState()
	{
		return state_;
	}

	virtual void loadData() = 0;
	virtual void writeData(const ResFileDataPtr& spResouces) = 0;

	virtual size_t getDataSize() const
	{
		return buffer_.size();
	}

	virtual ResFileDataPtr getResources() const = 0;

protected:
	FileID id_;
	ResourceFileState state_;
	FileStream fs_;
	FileStream::ByteArray buffer_;
};

typedef Stray::SharedPtr<ResourceFile>::type ResFilePtr;

}
}

#endif